package com.songleibing.project.pipeline.impl;

import com.songleibing.project.pipeline.Handler;
import com.songleibing.project.pipeline.HandlerChain;
import com.songleibing.project.pipeline.HandlerContext;
import com.songleibing.project.pipeline.HandlerResult;

public abstract class BaseHandler implements Handler {

    public abstract HandlerResult handle(HandlerContext context) throws Exception;

    public abstract void postHandle(HandlerContext context, Exception exception);

    @Override
    public void handle(HandlerChain chain, HandlerContext context) throws Exception {
        try {
            handle(context);
            chain.handle(context);
            postHandle(context, null);
        } catch (Exception e) {
            postHandle(context, e);
            throw e;
        }
    }
}
